/**
 * 
 */
package ar.edu.unq.svnpermission.ui.model;

import java.util.List;

import org.apache.wicket.model.IModel;

import ar.edu.unq.svnpermission.domain.Folder;
import ar.edu.unq.svnpermission.domain.Membership;
import ar.edu.unq.svnpermission.domain.Permission;
import ar.edu.unq.svnpermission.domain.User;
import ar.unq.edu.svnpermission.homes.PermissionHome;

/**
 * Representa el caso de uso para la administración de Permisos
 * @author nicolas
 */
public class Permissions extends UseCase{

	private static final long serialVersionUID = 1L;
	private Permission permission = new Permission(); 
	
	public Permissions(Folder folder)
	{
		this.getPermission().setFolder(folder);
	}
	
	public Permissions()
	{
		
	}
	
	/***
	 * Crea un nuevo Permiso en el repositorio
	 * @param permission La instancia de Permission que se va a persistir
	 * @author nicolas
	 */
	public void create()
	{
		this.getHome().create(this.getPermission());
	}
	
	/**
	 * Remueve un Permiso del repositorio
	 * @param permission La instancia de Permission que se va a remover
	 * @author nicolas
	 */
	public void remove(Permission permission)
	{
		this.getHome().delete(permission);
	}
	
	
	public List<Permission> getAll()
	{
		return this.getHome().getFolderPermissions(this.getFolder());
	}
	
	private PermissionHome getHome()
	{
		return this.getHome(Permission.class, PermissionHome.class);
	}

	public void setPermission(Permission permission) {
		this.permission = permission;
	}

	public Permission getPermission() {
		return permission;
	}
	
	/********************************************************************************
	 * ACCESSORS
	 ********************************************************************************/
	public Boolean getHasReadAccess()
	{
		return (this.getPermission().getAccess()==null ? false : this.getPermission().getHasReadAccess());
	}
	
	public void setHasReadAccess(Boolean mustRead)
	{
		this.getPermission().setHasReadAccess(mustRead);
	}

	public Boolean getHasWriteAccess()
	{
		return (this.getPermission().getAccess()==null ? false : this.getPermission().getHasWriteAccess());
	}
	
	public void setHasWriteAccess(Boolean mustWrite)
	{
		this.getPermission().setHasWriteAccess(mustWrite);
	}
	
	public void setWho(Membership membership)
	{
		this.getPermission().setWho(membership);
	}
		
	public Membership getWho()
	{
		return (this.getPermission().getWho());
	}
	
	public void setFolder (Folder folder)
	{
		this.getPermission().setFolder(folder);
	}
	
	public Folder getFolder ()
	{
		return (this.getPermission().getFolder()==null ? new Folder() : this.getPermission().getFolder());
	}
	
	
}
